package main
import (
	"fmt"
	"encoding/json"
)


// 注意：私有字段不会被序列化（小写的变量）
type Movie struct {
	Title	string  `json:"title"`
	Year  	int		`json:"year"`
	Price 	int		`json:"rmb"`
	Actors	[]string`json:"actors"`
}

func main(){
	mv := Movie{
		"罗生门",
		1877,
		114,
		[]string{"alan","noc","ghost-him"},
	}

	// struct转换成json
	jsonStr,err := json.Marshal(mv)
	if err != nil {
		fmt.Println("json marshal failed:",err)
		return
	}

	fmt.Printf("%s\n",jsonStr)

	// json转换成struct
	mv_cp := Movie{}
	if err := json.Unmarshal(jsonStr,&mv_cp);err ==  nil{
		fmt.Printf("%v\n",mv_cp)
	}

}